(deftemplate stare
    (slot valc1)
    (slot valc2)
    (slot nrOrdine)
 )

(deftemplate solutie
    (slot nrOrdine)
 )

(assert (solutie (nrOrdine 0)))

(assert (stare (valc1 0) (valc2 0) (nrOrdine ?n)));;starea initiala

(defrule umplere1
    (stare (valc1 ?c1)(valc2 ?c2) (nrOrdine ?n))
    (test (< ?c1 3))
    
    =>
    (bind ?nr (+ ?n 1))
    (assert (stare (valc1 3)(valc2 ?c2)(nrOrdine ?nr)))    
    (printout t "Starea nr=" ?nr "c1=3 c2=" ?c2 crlf)  
    )

(defrule umplere2
    (stare(valc1 ?c1)(valc2 ?c2) (nrOrdine ?n))
    (test (< ?c2 4))
     =>
    (bind ?nr (+ ?n 1))
    (assert(stare(valc1 ?c1)(valc2 4)(nrOrdine ?nr)))
    (printout t "Starea nr=" ?nr "c1=" ?c1 "c2=4" crlf)
    )

(defrule golire1
    (stare(valc1 ?c1)(valc2 ?c2)(nrOrdine ?n))
    (test (> ?c1 0))
    =>
    (bind ?nr (+ ?n 1))
    (assert(stare(valc1 0)(valc2 ?c2)(nrOrdine ?nr)))
    (printout t "Starea nr=" ?nr "c1=0 c2=" ?c2 crlf)
    )

(defrule golire2
    (stare(valc1 ?c1)(valc2 ?c2) (nrOrdine ?n))
    (test (> ?c2 0))
    =>
    (bind ?nr (+ ?n 1))
    (assert(stare(valc1 ?c1)(valc2 0)(nrOrdine ?nr)))
    (printout t"Starea nr=" ?nr "c1=" ?c1 "c2=0" crlf)
    )


    ;;if nu se poate folosi in partea dreapta doar in cazul in care avem nevoie de el la calcule
 
(defrule golire12
    (stare(valc1 ?c1)(valc2 ?c2))
    (test (and(> ?c1 0)(< ?c2 4)))
    =>
  (bind ?cantitateCeTrebuieTransferata (- 4 ?c2))
   (if (< ?cantitateCeTrebuieTransferata ?c1)
        then(bind ?cantitateTransferata ?cantitateCeTrebuieTransferata)
        else(bind ?cantitateTransferata ?c1)
   )
    (assert(stare(valc1(- ?c1 ?cantitateTransferata))(valc2 (+ ?c1 ?cantitateTransferata))))
)

(defrule golire21
    (stare(valc1 ?c1)(valc2 ?c2))
    (test (and(> ?c2 0)(< ?c1 3)))
    =>
  (bind ?cantitateCeTrebuieTransferata (- 3 ?c1))
   (if (< ?cantitateCeTrebuieTransferata ?c2)
        then(bind ?cantitateTransferata ?cantitateCeTrebuieTransferata)
        else(bind ?cantitateTransferata ?c2)
   )
     (assert(stare(valc2(- ?c2 ?cantitateTransferata))(valc1 (+ ?c2 ?cantitateTransferata))))
)

;;trebuie sa construim o metoda pt scoaterea starilor duplicat

(run)